// 分装请求

import { message } from "ant-design-vue";
import axios from 'axios'

export const baseURL = 'http://192.168.1.250:17001/'
const request = axios.create({
  baseURL: 'http://192.168.1.250:17001/',
  timeout: 5000
})

// 请求拦截
request.interceptors.request.use((config) => {
  const token = sessionStorage.getItem('token')
  if (token) {
    config.headers = {
      ...config.headers,
      token
    }
  }
  return config
})

// 响应拦截
request.interceptors.response.use((res) => {
  console.log(res);

  return res.data
}, (error) => {
  // 全局错误提示
  message.error(error.message)
  return Promise.reject(error)
}
)

export default request